namespace DotNetNuke.Services.Cache.BroadcastPollingCachingProvider
{
    using DotNetNuke.Common;
    using DotNetNuke.Services.Cache;
    using DotNetNuke.Services.Exceptions;
    using DotNetNuke.Services.Scheduling;
    
    using System;
    using System.Collections;

    public class Poll : SchedulerClient
    {
        public Poll(ScheduleHistoryItem objScheduleHistoryItem)
        {
            this.ScheduleHistoryItem = objScheduleHistoryItem;
        }

        public override void DoWork()
        {
            try
            {
                ArrayList arr = new Controller().GetBroadcasts(Globals.ServerName);
                int refIntHelperL0 = arr.Count - 1;
                for (int i = 0; i <= refIntHelperL0; i++)
                {
                    BroadcastInfo objBroadcastInfo = (BroadcastInfo) arr[i];
                    if (objBroadcastInfo.BroadcastType == "RemoveCachedItem")
                    {
                        CachingProvider.Instance().Remove(objBroadcastInfo.BroadcastMessage);
                    }
                    this.ScheduleHistoryItem.AddLogNote("Broadcast Type: " + objBroadcastInfo.BroadcastType + ", Broadcast Message: " + objBroadcastInfo.BroadcastMessage + "\r");
                }
                this.ScheduleHistoryItem.Succeeded = true;
            }
            catch (Exception exception1)
            {

                Exception exc = exception1;
                this.ScheduleHistoryItem.Succeeded = false;
                this.ScheduleHistoryItem.AddLogNote(string.Format("An error ocurred polling for server broadcasts.", exc.ToString()));
                this.Errored(ref exc);
                DotNetNuke.Services.Exceptions.Exceptions.LogException(exc);

            }
        }
    }
}

